#ifndef CAMERA_CLASS_H_INCLUDED
#define CAMERA_CLASS_H_INCLUDED
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include "MvCameraControl.h"
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <opencv2/video/video.hpp>
#include <thread>

class camera
{
    private:
        void* handle;
        bool g_bExit;
        int nRet;
        unsigned int g_nPayloadSize;
        unsigned char *pDataForRGB;
        MV_CC_DEVICE_INFO* pDeviceInfo;
        MV_CC_DEVICE_INFO_LIST stDeviceList;
        MVCC_INTVALUE stParam;
        MV_FRAME_OUT stOutFrame;
        MV_CC_PIXEL_CONVERT_PARAM CvtParam;

        float current_exposure;
        float current_gain;
        int adaptive_counter;
        float brightness_history[10]; // 存储最近10帧的亮度
        int brightness_index;

        // std::atomic<bool> m_running{false};
        // std::thread m_capture_thread;
        // void capture_loop();

    public:
        camera();
        void PrintDeviceInfo();
        void close_cam();
        void start_cam();
        void get_pic(cv::Mat * srcimg);

        void adaptiveExposureControl(cv::Mat& frame);
        float calculateBrightness(cv::Mat& frame);
        void optimizeForDetection();

        // void start_continuous_capture();
        // void stop_continuous_capture();
        // bool get_latest_frame(cv::Mat& frame);
};
#endif // CAMERA_CLASS_H_INCLUDED
